<template>
	<view class="uni_info">
		<!-- 选项卡切换 -->
		<view class="uni_infoNumInfo">
			<view class="uni_headerInfo">
				<view class="uni_tabs">
					<u-tabs :list="list" :is-scroll="false" :current="current" @change="change"></u-tabs>
				</view>
				<view class="uni_line"></view>
			</view>
			<!-- 账号信息 -->
			<view class="uni_numInfo" v-show="showInfo">
				<u-form :model="forms" ref="uForm" label-position="top" label-width="120rpx">
					<u-form-item label="账号" prop="usercode">
						<u-input v-model="forms.usercode" :border="true" placeholder="请输入账号" />
					</u-form-item>
					<u-form-item label="密码" prop="pwd">
						<u-input v-model="forms.pwd" type="password" :border="true" placeholder="请输入密码" />
					</u-form-item>
					<u-form-item>
						<view class="uni_jump" @click="goIndex">
							暂时跳过绑定
						</view>
					</u-form-item>
				</u-form>
				<view class="uni_btn" @click="btnHandler">
					<view class="uni_fs">
						确定
					</view>
				</view>
			</view>
			<!-- 班级信息 -->
			<view class="uni_classInfo" v-show="showInfo == false">
				<!-- 学校 -->
				<view class="uni_classSchool">
					<view class="uni_schooltop">学校</view>
					<view class="uni_schoolbtm">
						<u-input v-model="xuexiaoValue" :type="type" :border="border" @click="showXuexiao = true"
							placeholder="请选择学校" />
<<<<<<< HEAD
						<u-action-sheet :list="xuexiaoActionSheetList" v-model="showXuexiao"
=======
						<u-action-sheet :list="xuexiaoActionSheetList" :search="true" v-model="showXuexiao"
>>>>>>> test
							@click="actionSheetCallback" type="bottom">
						</u-action-sheet>
						<view class="uni_kong"></view>
					</view>
				</view>
				<!-- 学级 -->
				<view class="uni_classSchoolLevel">
					<view class="uni_schooltop">学级</view>
					<view class="uni_schoolbtm">
						<u-input v-model="xuejiValue" :type="type" :border="border" @click="showXueji = true"
							placeholder="请选择学级" />
						<u-action-sheet :list="xuejiActionSheetList" v-model="showXueji" @click="actionSheetCallback"
							type="bottom"></u-action-sheet>
						<view class="uni_kong"></view>
					</view>
				</view>
				<!-- 专业 -->
				<view class="uni_classSchoolProfession">
					<view class="uni_schooltop">专业</view>
					<view class="uni_schoolbtm">
						<u-input v-model="zhuanyeValue" :type="type" :border="border" @click="showZhuanye = true"
							placeholder="请选择专业" />
						<u-action-sheet :list="zhuanyeActionSheetList" v-model="showZhuanye"
							@click="actionSheetCallback" type="bottom"></u-action-sheet>
						<view class="uni_kong"></view>
					</view>
				</view>
				<!-- 班级 -->
				<view class="uni_classSchoolGrade">
					<view class="uni_schooltop">班级</view>
					<view class="uni_schoolbtm">
						<u-input v-model="banjiValue" :type="type" :border="border" @click="showBanji = true"
							placeholder="请选择班级" />
						<u-action-sheet :list="banjiActionSheetList" v-model="showBanji" @click="actionSheetCallback"
							type="bottom"></u-action-sheet>
						<view class="uni_kong"></view>
					</view>

				</view>

				<!-- 提示 -->
				<view class="uni_tips">
					{{tipsInfoclass}}
				</view>
				<!-- 按钮 -->
				<view class="uni_btn" @click="btnHandlerClass">
					<view class="uni_fs">
						确定
					</view>
				</view>
				<!-- 暂时跳过 -->
				<view class="uni_jump" @click="goIndex">
					暂时跳过绑定
				</view>
			</view>
		</view>


	</view>
</template>

<script>
	export default {
		data() {
			return {
<<<<<<< HEAD
=======
				tips: {
					text: '在水一方',
					color: '#909399',
					fontSize: 24
				},
>>>>>>> test
				keyword: '',
				showInfo: true,
				prisonInfo: {
					textValue: '',
					passwordValue: '',
				},
				tipsInfo: '温馨提示:绑定账号后,可通过已绑定账号登录',
				tipsInfoclass: '温馨提示：若已绑定手机号，账号密码均默认为手机号,若未绑定，请去我的—设置内进行绑定。',
				list: [{
					name: '绑定账号'
				}, {
					name: '绑定班级'
				}, ],
				current: 0,

				type: 'select',

				xuexiaoValue: '',
				showXuexiao: false,
				xuexiaoActionSheetList: [],
<<<<<<< HEAD
=======
				xuexiaoV: '',
>>>>>>> test

				xuejiValue: '',
				initializeXueJiValue: '',
				showXueji: false,
				xuejiActionSheetList: [],
				xuejiList: [],

				zhuanyeValue: '',
				showZhuanye: false,
				zhuanyeActionSheetList: [],

				banjiValue: '',
				showBanji: false,
				banjiActionSheetList: [],
				forms: {
					openid: uni.getStorageSync("openid"),
					usercode: '',
					pwd: '',
					mobile: uni.getStorageSync("mobile"),
				},
				rules: {
					usercode: [{
						required: true,
						message: '请输入账号',
						trigger: ['change', 'blur'],
					}],
					pwd: [{
						required: true,
						message: '请输入密码',
						trigger: ['change', 'blur'],
					}],
				},
				openid: uni.getStorageSync("openid"),
				form: {
					phone: "",
					schoolid: "",
					schoolname: "",
					zyid: "",
					zyname: "",
					xj: "",
					xjname: "",
					bjid: "",
					bjname: ""
				},
			};
		},
		onLoad() {
			// 学校
			this.schoollist()
			this.xjlist()
		},
<<<<<<< HEAD
		methods: {
=======
		watch: {
			xuexiaoValue(newWord) {
				// 当搜索关键词为空时触发自动搜索
				if (newWord.trim() === '') {
					this.schoollist();
				}
			}
		},
		methods: {
			searchFatherHand(value) {
				console.log('这是子组件传过来的', value)
				this.xuexiaoV = value
				this.schoollist(this.xuexiaoV)
			},
>>>>>>> test
			goIndex() {
				uni.reLaunch({
					url: "/pages/index/index"
				})
			},
			// 学校
<<<<<<< HEAD
			schoollist() {
				this.$api.post({
					url: '/yschool/pageSchoollist'
				}).then(res => {
					console.log(res, '查看学校的数量')
					res.list.list.forEach(item => {
=======
			// schoollist() {
			// 	this.$api.post({
			// 		url: '/yschool/pageSchoollist'
			// 	}).then(res => {
			// 		console.log(res, '查看学校的数量')
			// 		res.list.list.forEach(item => {
			// 			this.xuexiaoActionSheetList.push({
			// 				text: item.name,
			// 				schoolid: item.id
			// 			})
			// 		})
			// 	})
			// },
			schoollist(val) {
				console.log(val, 'val')
				let opts = {
					url: '/yschool/pageSchoollist',
					method: 'post'
				};
				let params = {
					searchText: this.xuexiaoV == '' && this.xuexiaoValue == '' ? this.xuexiaoValue : val,
					pageNum: 1,
					pageSize: 6000
				};
				console.log(params, '条件')
				this.$api.post(opts, params).then(res => {
					console.log(res, '查看学校的数量')
					this.xuexiaoActionSheetList = []
					let resList = res.list.list.slice(0, 10)
					resList.forEach(item => {
>>>>>>> test
						this.xuexiaoActionSheetList.push({
							text: item.name,
							schoolid: item.id
						})
					})
				})
			},
			// 学级
			xjlist() {
				console.log(111)
				this.$api.post({
					url: '/comm/getXj'
				}).then(res => {
					console.log(res, '学级')
					if (res.code == 0) {
						// this.xuejiActionSheetList = res.list
<<<<<<< HEAD
=======
						this.xuejiActionSheetList = []
>>>>>>> test
						this.xuejiActionSheetList = res.list.map(item => {
							return {
								text: item,
							}
						});
						if (this.form.xj == '') {
							this.form.xjname = this.xuejiActionSheetList[0] + '级';
							this.form.xj = this.xuejiActionSheetList[0];
						}
					}
				})
			},
			// 专业
			zyList() {
				let params = {
					schoolid: this.form.schoolid,
				}
				this.$api.post({
					url: '/dzy/list'
				}, params).then(res => {
					this.zhuanyeActionSheetList = res.list.map(item => {
						return {
							text: item.zymc,
							zyid: item.zydm
						}
					})

				})
			},

			// 班级
			bjList() {
				let params = {
					schoolid: this.form.schoolid,
					zydm: this.form.zyid,
					xj: this.form.xj
				}
				console.log(params, '获取班级携带的参数')
				// console.log(params.schoolid, '111学校ID')
				// console.log(params.zyid, '222专业')
				// console.log(params.xj, '333学籍')
				this.$api.post({
					url: '/dclass/bjlist'
				}, params).then(res => {
					console.log(res, '获取班级的数据')
					this.banjiActionSheetList = res.list.map(item => {
						return {
							text: item.bjmc,
							id: item.id
						}
					})
				})

			},

			change(index) {
				this.current = index;
				this.showInfo = !this.showInfo
				console.log(index, 'index')
			},

			actionSheetCallback(index) {
				// 学级
				if (this.showXueji) {
					this.xuejiValue = this.xuejiActionSheetList[index].text;
					this.form.xj = this.xuejiActionSheetList[index].text
					// 获取专业的数据
					this.zyList()
					this.showXueji = false;
					// 专业
				} else if (this.showZhuanye) {
					this.zhuanyeValue = this.zhuanyeActionSheetList[index].text;
					this.form.zyid = this.zhuanyeActionSheetList[index].zyid;
					// console.log(this.form.zyid, '获取班级专业的数据')
					// 班级的数据
					this.bjList()
					this.showZhuanye = false;
					// 班级
				} else if (this.showBanji) {
					this.banjiValue = this.banjiActionSheetList[index].text;
					this.form.bjid = this.banjiActionSheetList[index].id;
					this.showBanji = false;
					// 学校
				} else if (this.showXuexiao) {
					this.xuexiaoValue = this.xuexiaoActionSheetList[index].text;
					// 获取选择的当前学校的ID
					this.form.schoolid = this.xuexiaoActionSheetList[index].schoolid;
					// 学级的数据
					this.xjlist()
					// console.log(this.form.schoolid, 'this.form.schoolidthis.form.schoolidthis.form.schoolid')
					this.showXuexiao = false
				}
			},
			// 点击确定
			btnHandler() {
				this.$refs.uForm.validate(valid => {
					if (valid) {
						let opts = {
							url: '/bindPlatform',
							method: 'post'
						};
						this.$api.post(opts, this.forms).then(res => {
							if (res.code == 0) {
								uni.showToast({
									title: "绑定成功",
									icon: 'none'
								})
								uni.setStorageSync("user", res.user)
								uni.setStorageSync("currSchool", res.school)
								uni.setStorageSync("roles", res.roles);
								uni.setStorageSync('role', res.roles.filter(o => o != `jyzz`)[0]);
								uni.reLaunch({
									url: "/pages/index/index"
								})
							} else if (res.code == 10002) {
								uni.showToast({
									title: res.msg,
									icon: 'none'
								})
							} else if (res.code == 10003) {
								uni.showToast({
									title: res.msg,
									icon: 'none'
								})
							} else {
								uni.showToast({
									title: res.msg,
									icon: 'none'
								})
							}

						})
					} else {
						console.log('验证失败');
					}
				});

			},
			btnHandlerClass() {
				// this.xuejiValue = ''
				// this.zhuanyeValue = ''
				// this.banjiValue = ''
				// this.xuexiaoValue = ''
				let opts = {
					url: '/bindClass',
					method: 'post'
				};
				let params = {
					openid: uni.getStorageSync("openid"),
					schoolid: this.form.schoolid,
					xj: this.form.xj,
					zydm: this.form.zyid,
					classid: this.form.bjid,
					name: uni.getStorageSync("user").name,
					mobile: uni.getStorageSync("mobile"),
					sn: ''
				}
				this.$api.post(opts, params, true).then(res => {
					if (res.code == 0) {
						uni.showToast({
							title: "绑定成功",
							icon: 'none'
						})
						uni.setStorageSync("user", res.user);
						uni.setStorageSync('token', res.token);
						uni.setStorageSync("currSchool", res.school)
						if (res.roles != undefined) {
							uni.setStorageSync("roles", res.roles);
							uni.setStorageSync('role', res.roles.filter(o => o != `jyzz`)[0]);
						}
						setTimeout(() => {
							uni.reLaunch({
								url: "/pages/index/index"
							})
						}, 1000)

					} else if (res.code == 10002) {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					} else if (res.code == 10003) {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					} else {
						uni.showToast({
							title: res.msg,
							icon: 'none'
						})
					}

				})
			}
		},
		onReady() {
			this.$refs.uForm.setRules(this.rules);
		}
	}
</script>

<style lang="scss">
	.uni_info {
		width: 100%;
		height: 100%;
		background: #FFFFFF;

		// 账号
		.uni_infoNumInfo {
			position: relative;

			.uni_headerInfo {

				// 线条
				.uni_line {
					width: 100%;
					height: 1rpx;
					background: #F0F1F8;
				}
			}

			// 账号信息
			.uni_numInfo {
				padding: 40rpx;

				// 账号
				.uni_accountNumber {
					.uni_title {
						// width: 58rpx;
						margin: 78rpx 0 0 61rpx;
						height: 28rpx;
						font-size: 30rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #181623;
						line-height: 42rpx;
					}

					.uni_inNum {
						// box-sizing: border-box;

						.uni_inNum_Text {
							width: 646rpx;
							height: 96rpx;
							background: #F8F9FC;
							border: 1px solid #5257FF;
							border-radius: 16rpx;
							margin: 24rpx 0 0 52rpx;
							text-indent: 34rpx;
						}
					}
				}

				// 密码
				.uni_password {
					.uni_titleWord {
						margin: 50rpx 0 0 61rpx;
						height: 28rpx;
						font-size: 30rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #181623;
						line-height: 42rpx;
					}

					.uni_inPassword {
						.uni_inNum_psd {
							width: 646rpx;
							height: 96rpx;
							background: #F8F9FC;
							border: 1px solid #5257FF;
							border-radius: 16rpx;
							margin: 24rpx 0 0 52rpx;
							text-indent: 34rpx;
						}
					}
				}

				// 提
				.uni_tips {
					// width: 544rpx;
					height: 26rpx;
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #527FFF;
					line-height: 42rpx;
					margin: 35rpx 0 0 51rpx;
				}

				// 按钮
				.uni_btn {
					width: 552rpx;
					height: 96rpx;
					background: #5257FF;
					border-radius: 48rpx;
					position: fixed;
					left: 50%;
					bottom: 10%;
					transform: translateX(-50%) translateY(-50%);

					.uni_fs {
						width: 68rpx;
						height: 32rpx;
						font-size: 34rpx;
						font-family: PingFang SC;
						font-weight: 400;
						color: #FFFFFF;
						position: absolute;
						left: 50%;
						top: 50%;
						transform: translateX(-50%) translateY(-50%);
					}
				}

				// 暂时跳过绑定
				.uni_jump {
					position: fixed;
					left: 50%;
					bottom: 8%;
					transform: translateX(-50%) translateY(-50%);
					// width: 189rpx;
					height: 31rpx;
					font-size: 32rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #5257FF;
					line-height: 42rpx;
				}
			}

			// 班级信息
			.uni_classInfo {

				// 学校
				.uni_classSchool {
					width: 100%;
					display: flex;
					flex-direction: column;
					// align-items: center;
					// background: red;

					.uni_schooltop {
						margin: 78rpx 0 0 62rpx;
						// width: 57rpx;
						height: 28rpx;
						font-size: 30rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #181623;
						line-height: 42rpx;
					}

					// 设置学校的高度
					.u-drawer__scroll-view.data-v-52d4ddd1 {
						width: 100%;
						height: 600rpx !important;
						overflow-y: hidden;
					}

					.uni_schoolbtm {
						box-sizing: border-box;
						width: 646rpx;
						// width: 80%;
						height: 96rpx;
						background: #F8F9FC;
						border-radius: 16rpx;
						margin: 20rpx 0 0 52rpx;
						position: relative;

						// 出现滚动条
						.u-drawer-content {
							// background: #aef;
							overflow-y: auto;
						}

						.uni_kong {
							width: 0;
							height: 0;
							border-left: 20rpx solid transparent;
							border-right: 20rpx solid transparent;
							border-top: 30rpx solid #000;
							position: absolute;
							right: 24rpx;
							top: 36rpx;
							// background: red;
							opacity: .2;
						}

						.u-input {
							margin-top: 10rpx;

							// background: #afe;
							.u-input__input {
								// text-indent: 20rpx;
								width: 221rpx;
								height: 31rpx;
								font-size: 32rpx;
								font-family: PingFang SC;
								font-weight: 500;
								color: #181623;
								line-height: 42rpx;
								padding-left: 36rpx;
							}
						}
					}

				}

				// 学级
				.uni_classSchoolLevel {
					width: 100%;
					display: flex;
					flex-direction: column;
					// align-items: center;
					// background: red;


					.uni_schooltop {
						margin: 78rpx 0 0 62rpx;
						// width: 57rpx;
						height: 28rpx;
						font-size: 30rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #181623;
						line-height: 42rpx;
					}

					.uni_schoolbtm {
						box-sizing: border-box;
						width: 646rpx;
						// width: 80%;
						height: 96rpx;
						background: #F8F9FC;
						border-radius: 16rpx;
						margin: 24rpx 0 0 52rpx;
						position: relative;

						// 出现滚动条
						.u-drawer-content {
							// background: #aef;
							overflow-y: auto;
						}

						.uni_kong {
							width: 0;
							height: 0;
							border-left: 20rpx solid transparent;
							border-right: 20rpx solid transparent;
							border-top: 30rpx solid #000;
							position: absolute;
							right: 24rpx;
							top: 36rpx;
							// background: red;
							opacity: .2;
						}

						.u-input {
							margin-top: 10rpx;

							// background: #afe;
							.u-input__input {
								// text-indent: 30rpx;
								width: 221rpx;
								height: 31rpx;
								font-size: 32rpx;
								font-family: PingFang SC;
								font-weight: 500;
								color: #181623;
								line-height: 42rpx;
								padding-left: 36rpx;
							}
						}
					}
				}

				// 专业
				.uni_classSchoolProfession {
					width: 100%;
					display: flex;
					flex-direction: column;

					.uni_schooltop {
						margin: 78rpx 0 0 62rpx;
						// width: 57rpx;
						height: 28rpx;
						font-size: 30rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #181623;
						line-height: 42rpx;
					}

					.uni_schoolbtm {
						box-sizing: border-box;
						width: 646rpx;
						height: 96rpx;
						background: #F8F9FC;
						border-radius: 16rpx;
						margin: 24rpx 0 0 52rpx;
						position: relative;

						// 出现滚动条
						.u-drawer-content {
							// background: #aef;
							overflow-y: auto;
						}

						.uni_kong {
							width: 0;
							height: 0;
							border-left: 20rpx solid transparent;
							border-right: 20rpx solid transparent;
							border-top: 30rpx solid #000;
							position: absolute;
							right: 24rpx;
							top: 36rpx;
							// background: red;
							opacity: .2;
						}

						.u-input {
							margin-top: 10rpx;

							// background: #afe;
							.u-input__input {
								// text-indent: 30rpx;
								width: 221rpx;
								height: 31rpx;
								font-size: 32rpx;
								font-family: PingFang SC;
								font-weight: 500;
								color: #181623;
								line-height: 42rpx;
								padding-left: 36rpx;
							}
						}
					}

					.u-drawer__scroll-view.data-v-52d4ddd1 {
						width: 100%;
						height: 360rpx !important;
						overflow-y: hidden;
					}
				}

				// 班级
				.uni_classSchoolGrade {
					width: 100%;
					display: flex;
					flex-direction: column;


					.uni_schooltop {
						margin: 78rpx 0 0 62rpx;
						// width: 57rpx;
						height: 28rpx;
						font-size: 30rpx;
						font-family: PingFang SC;
						font-weight: 500;
						color: #181623;
						line-height: 42rpx;
					}

					.uni_schoolbtm {
						box-sizing: border-box;
						width: 646rpx;
						height: 96rpx;
						background: #F8F9FC;
						border-radius: 16rpx;
						margin: 24rpx 0 0 52rpx;
						position: relative;

						// 出现滚动条
						.u-drawer-content {
							// background: #aef;
							overflow-y: auto;
						}

						.uni_kong {
							width: 0;
							height: 0;
							border-left: 20rpx solid transparent;
							border-right: 20rpx solid transparent;
							border-top: 30rpx solid #000;
							position: absolute;
							right: 24rpx;
							top: 36rpx;
							// background: red;
							opacity: .2;
						}

						.u-input {
							margin-top: 10rpx;

							// background: #afe;
							.u-input__input {
								// text-indent: 30rpx;
								width: 221rpx;
								height: 31rpx;
								font-size: 32rpx;
								font-family: PingFang SC;
								font-weight: 500;
								color: #181623;
								line-height: 42rpx;
								padding-left: 36rpx;
							}
						}
					}


				}

				// 提示
				.uni_tips {
					// width: 544rpx;
					height: 26rpx;
					font-size: 26rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #527FFF;
					line-height: 42rpx;
					margin: 35rpx 0 0 51rpx;
				}

				// 按钮
				.uni_btn {
					width: 552rpx;
					height: 96rpx;
					background: #5257FF;
					border-radius: 48rpx;
					position: fixed;
					left: 50%;
					bottom: 10%;
					transform: translateX(-50%) translateY(-50%);

					.uni_fs {
						width: 68rpx;
						height: 32rpx;
						font-size: 34rpx;
						font-family: PingFang SC;
						font-weight: 400;
						color: #FFFFFF;
						position: absolute;
						left: 50%;
						top: 50%;
						transform: translateX(-50%) translateY(-50%);
					}
				}

				// 暂时跳过绑定
				.uni_jump {
					position: fixed;
					left: 50%;
					bottom: 8%;
					transform: translateX(-50%) translateY(-50%);
					height: 31rpx;
					font-size: 32rpx;
					font-family: PingFang SC;
					font-weight: 400;
					color: #5257FF;
					line-height: 42rpx;
				}
			}
		}
	}
</style>